package Test1;

import java.util.Random;

public class lian_xi_Demo3 extends Thread {
    static double money = 100;
    static int count = 3;
    static final double MIN=0.01 ;
    @Override
    public void run() {
        synchronized (lian_xi_Demo3.class) {
            if(count==0){
                System.out.println(getName()+"没有抢到红包");
            }else{
                double prize;
                if(count==1){
                    prize=money;
                }else{
                    Random r = new Random();
                    double bound = money - (3 - count) * MIN;
                    prize=r.nextDouble()*bound;
                    if(prize<MIN){
                        prize=MIN;
                    }
                }
                money-=prize;
                count--;
                System.out.println(getName()+"抢到了"+prize+"元");
                //System.out.println("还剩下"+money+"元");
            }
        }
    }
}
